﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StatelyCompiler;

namespace ObviousCode.Stately.Compiler.Parser
{
    public class Transition
    {
        public enum Kind { Unknown, Derail, Transition }
        public enum NodeType { State, WildCard, Wait }

        public Kind TransitionKind { get; private set; }

        public Token SourceState { get; private set; }
        public Token DestinationState { get; private set; }

        public NodeType SourceNodeType { get; private set; }
        public NodeType DestinationNodeType { get; private set; }

        private Transition(Kind kind)
        {
            TransitionKind = kind;
        }

        public static Transition For(Kind transitionKind, Token sourceState, Token finalState)
        {
            Transition transition = new Transition(transitionKind);

            transition.SourceState = sourceState;
            transition.DestinationState = finalState;

            transition.SourceNodeType = sourceState.Kind == Token.TokenType.Wildcard ? NodeType.WildCard : NodeType.State;
            transition.DestinationNodeType = finalState.Kind == Token.TokenType.Pipe ? NodeType.Wait : NodeType.State;

            return transition;
        }

        public override string ToString()
        {
            return "{0} {1} {2}".F(SourceState, TransitionKind, DestinationState);
        }
    }
}
